package org.micode.demo.db.dao;

import org.micode.demo.db.domain.dto.SysUserRoleDTO;
import org.micode.libs.dao.base.BaseAllDao;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户所属角色(sys_user_role) 实体类的Dao
 *
 * author: wutianbin
 */
@Mapper
public interface SysUserRoleDao extends BaseAllDao<SysUserRoleDTO> {

    // 非常规sql写这里--- xml 自动生成,不再手动在xml中写sql !!

    @Select("SELECT role_id " +
            " FROM sys_user_role " +
            " WHERE user_id = #{userId}")
    @ResultType(Long.class)
    List<Long> listRoleIdByUser(@Param("userId") Long userId);

    @Delete("delete from sys_user_role " +
            "  where role_id=#{roleId}")
    void deleteForRoleId(@Param("roleId") Long roleId);

    @Delete("delete from sys_user_role " +
            "  where user_id=#{userId}")
    void deleteForUserId(@Param("userId") Long userId);

}
